﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.actions {
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import flash.utils.*;
    import Classes.*;
    import Modules.guide.*;
    import Display.hud.components.*;
    import Display.peddlerUI.*;
    import Engine.*;

    public class GADisplayTarget extends GuideAction {

        public static const MODE_LOCATION:int = 0;
        public static const MODE_TILE:int = 1;
        public static const MODE_RELATIVE:int = 2;
        public static const MODE_TARGET_CLASS:int = 3;
        public static const MODE_TARGET_TYPE:int = 4;
        public static const MODE_ACTIVE_ROLL_CALL_TYPE:int = 5;
        public static const MODE_HUD:int = 1005;
        public static const MODE_PEDDLERBAR:int = 6;
        public static const MODE_DEFAULT:int = 0;

        protected var m_mode:Number = 0;
        protected var m_targetType:String;
        protected var m_xml:XMLList;
        protected var m_level:int = 0;
        protected var m_parent:DisplayObjectContainer = null;
        protected var m_target:DisplayObject;
        protected var m_targetClass:Class;
        protected var m_targetObjectNames:Array;
        protected var m_focus:Point;
        protected var m_size:Point;
        protected var m_style:int;
        protected var m_alpha:Number = 0;
        protected var m_showOutline:Boolean = false;
        protected var m_spotlightFunc:Function;

        public function GADisplayTarget(){
            this.m_targetObjectNames = [];
            super();
        }
        override public function createFromXml(_arg1:XML):Boolean{
            var _local11:DisplayObject;
            var _local12:Object;
            this.m_xml = checkAndGetElement(_arg1, this.m_targetType);
            if (!this.m_xml){
                return (false);
            };
            var _local2:String = this.m_xml.@mode;
            this.m_focus = new Point(Number(this.m_xml.@x), Number(this.m_xml.@y));
            if ((((Global.player.socialNetworkId == 1)) && ((_local2 == "location")))){
                this.m_focus.x = (this.m_focus.x - 97);
            };
            this.m_size = new Point(Number(this.m_xml.@w), Number(this.m_xml.@h));
            this.m_style = ((String(this.m_xml.@style))=="rect") ? GuideConstants.MASK_STYLE_RECTANGLE : GuideConstants.MASK_STYLE_ELLIPSE;
            var _local3:String = this.m_xml.@level;
            var _local4:String = this.m_xml.@parent;
            var _local5:String = this.m_xml.@target;
            var _local6:String = this.m_xml.@className;
            var _local7:String = this.m_xml.@typeName;
            var _local8:String = this.m_xml.@alpha;
            var _local9:String = this.m_xml.@showOutline;
            var _local10:String = this.m_xml.@spotLightFunc;
            if (_local3.length > 0){
                switch (_local3){
                    case "game":
                        this.m_level = GuideConstants.MASK_GAME;
                        break;
                    case "bottombar":
                        this.m_level = GuideConstants.MASK_GAME_AND_BOTTOMBAR;
                        break;
                    case "all":
                        this.m_level = GuideConstants.MASK_ALL_UI;
                        break;
                    case "specific":
                        this.m_level = GuideConstants.MASK_SPECIFIC;
                        break;
                    case "all_no_listen":
                        this.m_level = GuideConstants.MASK_NO_LISTEN;
                        break;
                    default:
                        return (false);
                };
            };
            this.m_parent = Global.ui;
            if (_local4.length > 0){
                _local11 = m_guide.getObjectByName(_local4);
                if (_local11 == null){
                    return (false);
                };
                this.m_parent = (_local11 as DisplayObjectContainer);
            };
            if (_local5.length > 0){
                _local11 = m_guide.getObjectByName(_local5);
                if (_local11 == null){
                    return (false);
                };
                this.m_target = (_local11 as DisplayObjectContainer);
            };
            if (_local6.length > 0){
                _local12 = getDefinitionByName(("Classes." + _local6));
                if (_local12 == null){
                    return (false);
                };
                this.m_targetClass = (_local12 as Class);
            };
            if (_local7.length > 0){
                this.m_targetObjectNames = _local7.split(",");
            };
            if (_local2.length > 0){
                _local2 = _local2.toLowerCase();
                switch (_local2){
                    case "location":
                        this.m_mode = MODE_LOCATION;
                        break;
                    case "tile":
                        this.m_mode = MODE_TILE;
                        break;
                    case "relative":
                        this.m_mode = MODE_RELATIVE;
                        break;
                    case "targetclass":
                        this.m_mode = MODE_TARGET_CLASS;
                        break;
                    case "targettype":
                        this.m_mode = MODE_TARGET_TYPE;
                        break;
                    case "activerollcalltype":
                        this.m_mode = MODE_ACTIVE_ROLL_CALL_TYPE;
                        break;
                    case "hud":
                        this.m_mode = MODE_HUD;
                        break;
                    case "peddlerbar":
                        this.m_mode = MODE_PEDDLERBAR;
                        break;
                    default:
                        return (false);
                };
            };
            if (_local8.length > 0){
                this.m_alpha = Number(_local8);
            };
            if (_local9.length > 0){
                this.m_showOutline = (int(_local9) == 1);
            };
            if ((((this.m_mode == MODE_RELATIVE)) && ((this.m_target == null)))){
                ErrorManager.addError("Relative mode requires a 'target' attribute!");
                return (false);
            };
            if ((((this.m_mode == MODE_TARGET_CLASS)) && ((this.m_targetClass == null)))){
                ErrorManager.addError("Target Class mode requires a 'className' attribute!");
                return (false);
            };
            this.m_spotlightFunc = (m_guide) ? m_guide.displaySpotLight : null;
            if (_local10.length > 0){
                this.m_spotlightFunc = (m_guide) ? (m_guide[_local10] as Function) : this.m_spotlightFunc;
            };
            return (true);
        }
        override public function enter():void{
            var _local1:Point;
            var _local2:Point;
            var _local3:GameObject;
            var _local4:Point;
            var _local5:Vector3;
            var _local6:GameObject;
            var _local7:MapResource;
            var _local8:Point;
            var _local9:Vector3;
            var _local10:HUDComponentContainer;
            var _local11:HUDComponentContainer;
            var _local12:PeddlerBar;
            var _local13:Point;
            var _local14:PeddlerCell;
            switch (this.m_mode){
                case MODE_RELATIVE:
                    _local1 = this.m_target.localToGlobal(this.m_focus);
                    this.m_spotlightFunc(this.m_parent, _local1, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    break;
                case MODE_LOCATION:
                    this.m_spotlightFunc(this.m_parent, this.m_focus, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    break;
                case MODE_TILE:
                    _local2 = IsoMath.tilePosToPixelPos(this.m_focus.x, this.m_focus.y);
                    _local2 = IsoMath.viewportToStage(_local2);
                    this.m_spotlightFunc(Global.ui, _local2, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    break;
                case MODE_TARGET_CLASS:
                    _local3 = GuideUtils.getGameObjectByClassName(this.m_targetClass);
                    if (!_local3){
                        this.m_focus = null;
                        break;
                    };
                    _local4 = _local3.getScreenPosition();
                    _local4 = IsoMath.viewportToStage(_local4);
                    _local5 = _local3.getDimensions();
                    _local4.x = (_local4.x + (_local5.x / 2));
                    _local4.y = (_local4.y + (_local5.y / 2));
                    this.m_focus = new Point(_local4.x, _local4.y);
                    if (this.m_spotlightFunc != null){
                        this.m_spotlightFunc(this.m_parent, this.m_focus, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    };
                    break;
                case MODE_TARGET_TYPE:
                case MODE_ACTIVE_ROLL_CALL_TYPE:
                    if (this.m_mode == MODE_TARGET_TYPE){
                        _local6 = GuideUtils.getGameObjectByTypeName(this.m_targetObjectNames[0]);
                    } else {
                        _local6 = GuideUtils.getActiveRollCallByTypeNames(this.m_targetObjectNames);
                    };
                    if (!_local6){
                        this.m_focus = null;
                        break;
                    };
                    if ((_local6 is MapResource)){
                        (_local6 as MapResource).refreshArrow();
                    };
                    _local7 = (_local6 as MapResource);
                    _local8 = IsoMath.viewportToStage(_local6.getScreenPosition());
                    _local9 = _local6.getDimensions();
                    if (((!(_local9)) && (_local7))){
                        _local9 = _local7.getItemImageDimensions();
                    };
                    if (_local9){
                        _local8.x = (_local8.x + (_local9.x / 2));
                        _local8.y = (_local8.y + (_local9.y / 2));
                    };
                    this.m_focus = new Point(_local8.x, _local8.y);
                    this.m_focus.x = (this.m_focus.x - 10);
                    if (this.m_spotlightFunc != null){
                        this.m_spotlightFunc(this.m_parent, this.m_focus, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    };
                    break;
                case MODE_HUD:
                    Utilities.toggleFullScreen();
                    _local10 = (Global.hud.getComponent("visitStack") as HUDComponentContainer);
                    if (_local10){
                        this.m_target = _local10.getComponent(HUDPeddlerComponent);
                        _local13 = new Point((_local10.x + 40), ((_local10.y + this.m_target.y) + 40));
                        this.m_focus = _local13;
                        if (this.m_spotlightFunc != null){
                            this.m_spotlightFunc(this.m_parent, this.m_focus, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                        };
                    };
                    break;
                case MODE_PEDDLERBAR:
                    Utilities.toggleFullScreen();
                    _local11 = (Global.hud.getComponent("visitStack") as HUDComponentContainer);
                    _local12 = PeddlerBar.getInstance();
                    if (_local11){
                        this.m_target = _local11.getComponent(HUDPeddlerComponent);
                        _local14 = _local12.getAvailableCell();
                        this.m_focus = new Point((120 + _local14.x), ((_local11.y + this.m_target.y) + 45));
                    };
                    if (this.m_spotlightFunc != null){
                        this.m_spotlightFunc(this.m_parent, this.m_focus, this.m_size, this.m_style, this.m_level, this.m_alpha, this.m_showOutline);
                    };
                    break;
            };
            super.enter();
        }
        override public function update(_arg1:Number):void{
            super.update(_arg1);
            super.removeState(this);
        }

    }
}//package Modules.guide.actions 
